#include "optionsdialogimpl.h"
#include "mainapp.h"
#include <QMessageBox>
//
OptionsDialogImpl::OptionsDialogImpl ( MainOptions * opt, QWidget * parent, Qt::WFlags f )
		: QDialog ( parent, f ), m_opt ( opt ) {
	setupUi ( this );
	params2controls();
}
//




void OptionsDialogImpl::on_okButton_clicked() {
	controls2params();
	emit saveall();
	accept();
}

void OptionsDialogImpl::on_applyButton_clicked() {
	controls2params();
	emit saveall();
}




void OptionsDialogImpl::params2controls() {
	OptionsHash *h = m_opt->options();
	emergeEdit->setText ( h->value ( "emerge" ).toString() );

	langComboBox->clear();
	langComboBox->insertItems ( 0, MainApp::supportedLanguages() );
	int i = langComboBox->findText ( h->value ( "lang" ).toString() );
	if ( i < 0 ) i = 0;
	langComboBox->setCurrentIndex ( i );

}

void OptionsDialogImpl::controls2params() {
	OptionsHash *h = m_opt->options();
	h->insert ( "emerge", emergeEdit->text() );

	if ( h->value ( "lang" ).toString() != langComboBox->currentText() ) {
		h->insert ( "lang", langComboBox->currentText() );
		MainApp::setTranslation ( h->value ( "lang" ).toString() );
		QMessageBox::information ( this, tr ( "Change language" ), tr ( "To take effect please restart application" ) );
	}
}
